package ${package.basePackage}.${package.moduleName}.service.impl;

import com.seal.commons.copiers.BeanMapper;
import ${package.basePackage}.${package.moduleName}.entity.${tableInfo.entityName};
import ${package.basePackage}.${package.moduleName}.bo.${tableInfo.boName};
import ${package.basePackage}.${package.moduleName}.service.${tableInfo.serviceName};
import ${package.basePackage}.${package.moduleName}.repository.${tableInfo.repositoryName};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.time.LocalDateTime;
import java.util.Optional;


/**
* 功能描述: <br/>
* @date:    ${createDateTime}<br/>
* @author   ${auther}
* @since    JDK 1.8
*/
@Service
public class ${tableInfo.serviceImplName} implements ${tableInfo.serviceName} {

    @Autowired
    private ${tableInfo.repositoryName} ${tableInfo.repositoryName?uncap_first};

    @Override
    public ${tableInfo.boName} create(${tableInfo.boName} bo) {
        ${tableInfo.entityName} entity = bo.toEntity(${tableInfo.entityName}.class);
        entity.setCreateDateTime(LocalDateTime.now());
        entity = ${tableInfo.repositoryName?uncap_first}.saveAndFlush(entity);
        bo.parse(entity);
        return bo;
    }

    @Override
    public ${tableInfo.boName} getById(${tableInfo.pkField.javaType} id) {
        Optional<${tableInfo.entityName}> optional = ${tableInfo.repositoryName?uncap_first}.findById(id);
        if(optional.isPresent()){
            return BeanMapper.cglibCopy(optional.get(), ${tableInfo.boName}.class);
        }
        return null;
    }


}